from flask import Blueprint, request
from utilsapp.mysql_con import db_pagelist, db_fetchone, db_delete, db_update
from utilsapp.common import assign_value, parsing_data_id

bluePrint = Blueprint('message', __name__)
tableName = 'message'


# 分页查询
@bluePrint.route('/getlist', methods=["post"])
def table_list():
    sql = f"""SELECT * from message"""
    query = " where 1 = 1 "
    a = request.json
    sql += query
    sql += " order by sent_time desc"
    res = db_pagelist(sql, a["page"])
    return res


@bluePrint.route('/delete', methods=["post"])
def a():
    id_ = assign_value(request.json, "id")
    return db_delete('message', f'WHERE id = %s',
                     {'id_': id_})